home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / May MacUser Program.cpt / miniGenApp Src / Display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-29  |  3.7 KB  |  122 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             Display.c
  3.     
  4.     DESCRIPTION:     Drawing functions
  5.  
  6.     AUTHOR:            Kurt W.G. Matthies
  7.         
  8.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  9.     
  10.     Revision History:
  11.     ==========================================================
  12.     3.30.90    -    May 1990 MacUser Release
  13.     ==========================================================
  14.  
  15.    ***************************************************************************** */
  16. #include "AppGlobals.h"
  17.  
  18. #include "DisplayPr.h"
  19.  
  20. /* --------------------------------------------------------------------------------
  21.     makeFrameRect -    create the window frame rectangle, ie, the content - scroll bar
  22.     3.30.90kwgm        areas
  23. ----------------------------------------------------------------------------------- */
  24. Rect *
  25. makeFrameRect (theWindow, frameRectPtr)
  26.     WindowPtr    theWindow;
  27.     Rect        *frameRectPtr;
  28. {
  29.     Rect        localRect;
  30.     
  31.     localRect = theWindow->portRect;    /* get port rect */
  32.     
  33.     localRect.right -= kScrollBarSize;    /* take out scroll bars */
  34.     localRect.bottom -= kScrollBarSize;
  35.     
  36.     if (frameRectPtr)
  37.         *frameRectPtr = localRect;
  38.  
  39.     return (&localRect);
  40.     
  41. } /* makeFrameRect */
  42.  
  43. /* --------------------------------------------------------------------------
  44.     setFrameClip -    set the port's clip rect to the content region of the window
  45.     3.30.90kwgm        minus the scroll bar area
  46. ----------------------------------------------------------------------------- */
  47. void
  48. setFrameClip (theWindow, frameRectPtr)
  49.     WindowPtr        theWindow;
  50.     Rect            *frameRectPtr;
  51. {
  52.     Rect            frameRect;
  53.     
  54.     makeFrameRect (theWindow, &frameRect);
  55.     ClipRect (&frameRect);
  56.     
  57.     if (frameRectPtr)
  58.         *frameRectPtr = frameRect;
  59.     
  60. } /* setFrameClip */
  61.  
  62. /*--------------------------------------------------------------------------------
  63.     drawDocContents -    draw the contents of theDoc. The contents are taken from
  64.     3.30.90kwgm            the string resource. Try using ResEdit to change the string
  65. ---------------------------------------------------------------------------------- */
  66. void 
  67. drawDocContents (theDoc)
  68.     DocPtr             theDoc;
  69. {
  70.     register short    len, portWidth, strWidth, height, lineHeight, portHeight;
  71.     FontInfo        fInfo;
  72.     Str255            helloStr;
  73.     
  74.     GetFontInfo (&fInfo);
  75.     GetIndString (helloStr, kNameStrRsrc, kHelloStrID);
  76.     
  77.     len = height = 0;
  78.     lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
  79.     
  80.     portWidth = ((GrafPtr)theDoc)->portRect.right - ((GrafPtr)theDoc)->portRect.left;
  81.     portHeight = ((GrafPtr)theDoc)->portRect.bottom - ((GrafPtr)theDoc)->portRect.top;
  82.     strWidth = StringWidth (helloStr);
  83.  
  84.     /* fill the window with the string */
  85.     
  86.     MoveTo (0, lineHeight);
  87.     while (height < portHeight)
  88.     {        
  89.         while (len < portWidth)
  90.         {
  91.             DrawString (helloStr);        /* draw until the edge of the window */
  92.             len += strWidth;
  93.         }
  94.         
  95.         len = 0;
  96.         height += lineHeight;    
  97.  
  98.         MoveTo (0, height);        /* move the pen to the next line */
  99.     }
  100.  
  101.     /* 
  102.         this algorithm starts at the top of the window, and draws the string
  103.         using DrawString until the right edge of the window is reached.
  104.         Then it moves the pen down a line, and repeats the process.
  105.         This continues until the pen falls of the bottom of the window.
  106.         
  107.         Notice that the beginning of each new line restarts the string.
  108.         
  109.         Can you modify this algoritm to wrap text around the window, i.e.,
  110.         how would change this loop so that the next line drawn would
  111.         pick up where the end of the previous line left off?? 
  112.         Like in Hello World? Hello World? Hello World? Hello World? Hel
  113.         lo World? He ...
  114.  
  115.     */
  116.         
  117. } /* drawDocContents */
  118.  
  119. /* ===============================  EOF  =======================================
  120.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  121. ================================================================================ */
  122.